from django.utils.deprecation import MiddlewareMixin

class CorsMiddleware(MiddlewareMixin):
    def process_response(self, request, response):
        response["Access-Control-Allow-Origin"] = "*"  # 允许所有源的跨域请求
        # 可选：如果你想要允许特定的源，可以使用下面这行代码，将 * 替换为你想要允许的源
        # response["Access-Control-Allow-Origin"] = "http://example.com"
        return response
